package com.wuyou.mid;

/**
 * 1456. 定长子串中元音的最大数目
 *
 * @Date 2024/11/29 11:06
 * @Author 无忧
 */
public class MaxVowels {

    public static void main(String[] args) {
        String s = "aeiou";
        int k = 2;
        System.out.println(maxVowels(s, k));
    }


    public static int maxVowels(String s, int k) {
        int res = 0, l = 0, r = 0, length = s.length(), count = 0, countK = 0;
        char[] cs = s.toCharArray();
        while (r < length) {
            if (detect(cs[r])) {
                count++;
            }
            if(r < k - 1){
                r++;
                continue;
            }
            if (r >= k - 1) {
                res = Math.max(count, res);
                if (detect(cs[l])) {
                    count--;
                }
                l++;
            }
            r++;
            if(res == k){
                break;
            }
        }
        return res;
    }

    private static boolean detect(char ch) {
        return (ch=='a'||ch=='o'||ch=='e'||ch=='i'||ch=='u');
    }
}
